package top.linuyx.controller;

import org.apache.shiro.authz.annotation.RequiresRoles;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import top.linuyx.pojo.response.ResponseData;
import top.linuyx.pojo.vo.QueryProductsVO;
import top.linuyx.service.QueryProductsService;

import java.util.List;

/**
 * @Author Cucumber
 * @Description：与前端交互的用户查询商品方法
 * @Date Created in 2021-04-09 9:28
 */
@Controller
@RequestMapping("/commodity")
public class QueryProductsController {

    @Autowired
    private QueryProductsService queryProductsService;

    /**
     * 调用Service层实现的查询商品的方法
     * @param input：用户输入的字符串
     * @return：查询结果
     * @throws Exception
     */
    @GetMapping(name = "查询商品")
    @RequiresRoles("user")
    @ResponseBody
    public ResponseData<List<QueryProductsVO>> getProducts(String input) throws Exception {
        List<QueryProductsVO> productsList = queryProductsService.queryProducts(input);
        return ResponseData.success("查询成功",productsList);
    }

}
